#include "TipArea.h"
#include <QPainter>
#include <QFont>

TipArea::TipArea()
{
    background=QPixmap("resource/tip.png");
    height=background.height();
    width=background.width();
    setVisible(0);
    box=new QComboBox;
    box->setSizeAdjustPolicy(QComboBox::AdjustToContents);
    boxItem=new QGraphicsProxyWidget;
    boxItem->setWidget(box);
    boxItem->setParentItem(this);
    boxItem->setPos(0.35*width,0.5*height);
    boxItem->setVisible(0);
}
QRectF TipArea::boundingRect() const
{
    return QRectF(0, 0, width, height);
}

void TipArea::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    QFont font;
    font.setPixelSize(20);
    painter->setFont(font);
    painter->setPen(QColor(Qt::white));
    painter->drawPixmap(0, 0, background);
    painter->drawText(QRectF(0, 0, width, height*0.9),Qt::AlignCenter,msg);
}

void TipArea::reset()
{
    setVisible(0);
    box->clear();
    boxItem->setVisible(0);
}

void TipArea::addBoxItem(QString text)
{
    box->addItem(text);
}

void TipArea::showBox()
{
    setVisible(1);
    boxItem->setVisible(1);
    update();
}

void TipArea::setMsg(QString msg)
{
    this->msg=msg;
    setVisible(1);
    update();
}
